#pragma once

#include <iostream>
#include <istream>
#include <fstream>
#include <cstdlib>
#include <cassert>

void game_setup(I_GAME &g)
{
	// setup mersenne twister values
	mt_setup((unsigned int) std::time(NULL));
	
	// fill tables with randoms to use with the keys and locks
	create_zobrist(g.ZKEYS, g.ZLOCK);
	
	// setup the main search agent for this game
	setup_search_agent(g.SEARCH_AGENT);
	g.SEARCH_AGENT.eval_func = main_static_eval;
	
	// insert piece values into the array from the file
	std::ifstream inp("books/values/pieces.inp");
	trace_assert(inp.is_open(), "FAILED to load material value input file. File not found or I/O error.");
	
	// get piece values from file
	int i, v; for (i = I_PIECE_PA; i <= I_PIECE_KI; i += 2) // for each piece type
	{ 
		// read value
		inp >> v;
		
		// set value to this amount
		g.PIECE_VALUE[i + I_SIDE_WHITE] = v;
		g.PIECE_VALUE[i + I_SIDE_BLACK] = v;
	};
	
	// close stream
	inp.close();
	trace(TRACE_LEVEL_DEBUG, "SUCCESSFULLY loaded material value array from file.");
	
	// load the opening book into memory
	g.OPEN_BOOK = load_array<ZRANDOM>("books/open/book.inp");
	
	// load the static evaluation values
	g.EVAL_VALUES = load_array<FLT_NUMBER>("books/values/eval.inp");
	
	// load position boards
	load_position_boards(&g.POS_BOARDS, "books/values/pos.inp");
	
	// setup player profiles
	g.PLAYER_PROFILES[I_SIDE_WHITE] = I_PLAYER_COMPUTER_EASY;
	g.PLAYER_PROFILES[I_SIDE_BLACK] = I_PLAYER_COMPUTER_EASY;
};

// applies a single move to the current position
void apply_player_halfmove()
{
	// get the current player's status and profile
	int cur_player = CURRENT_POSITION->col;
	int prf_player = GAME.PLAYER_PROFILES[cur_player];
	
	if (prf_player == I_PLAYER_HUMAN) get_human_move(CURRENT_POSITION);
	else apply_best_move(CURRENT_POSITION, prf_player);
};

// apply two halfmoves (one on each player)
void apply_player_fullmove()
{
	apply_player_halfmove();
	apply_player_halfmove();
};

void get_human_move(I_CHESS_POSITION *p)
{
	return;
};
